package com.fin.zw.intelligentbot.controller;


import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.VerbalNode;
import com.fin.zw.intelligentbot.model.request.VerbalNodeRequest;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.VerbalNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/verbalNode")
@Api(value = "话术节点信息", description = "话术节点信息")
public class VerbalNodeController {

    @Autowired
    private VerbalNodeService verbalNodeService;


    @GetMapping("/fetchPage")
    @ApiOperation(value = "话术节点信息查询", notes = "话术节点信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<VerbalNode>> queryVerbalNode(Pageable pageable,
                                                            VerbalNodeRequest request,
                                                            @ApiIgnore @CurrentUser SessionModel sessionModel) {
        Page<VerbalNode> page = verbalNodeService.queryNode(pageable, request, sessionModel);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/fetch")
    @ApiOperation(value = "话术节点信息查询", notes = "话术节点信息查询")
    public ResponseEntity<List<VerbalNode>> getVerbalNode(@ApiIgnore @CurrentUser SessionModel sessionModel) {
        List<VerbalNode> verbalNodes = verbalNodeService.getVerbalNode( sessionModel);
        return ResponseEntity.ok().body(verbalNodes);
    }


    @PostMapping("/add")
    @ApiOperation(value = "话术节点信息添加", notes = "话术节点信息添加")
    public ResponseEntity<Void> createVerbalNode(@RequestBody VerbalNodeRequest request,
                                                 @ApiIgnore @CurrentUser SessionModel sessionModel) {
        verbalNodeService.createNode(request, sessionModel);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/update")
    @ApiOperation(value = "话术节点信息更新", notes = "话术节点信息更新")
    public ResponseEntity<Void> updateVerbalNode(@RequestBody VerbalNodeRequest request) {
        verbalNodeService.updateNode(request);
        return ResponseEntity.ok().build();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "话术节点信息删除", notes = "话术节点信息删除")
    public ResponseEntity<Void> deleteById(@PathVariable String id) {
        verbalNodeService.deleteNode(id);
        return ResponseEntity.ok().build();
    }
}